package com.example.hl.gobang.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.example.hl.gobang.R;
import com.example.hl.gobang.view.WuziqiPanel;

/**
 * Created by My Family on 2018/6/19.
 */

public class PlayActivity extends AppCompatActivity implements View.OnClickListener {

    Button btnNewRound;
    Button btnBackup;
    Button btnLeave;
    private WuziqiPanel mWuziqi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play);

        setTitle("五子棋");

        mWuziqi = findViewById(R.id.wuziqi);
        btnNewRound = findViewById(R.id.btn_new);
        btnBackup = findViewById(R.id.btn_backp);
        btnLeave = findViewById(R.id.btn_leave);

        btnLeave.setOnClickListener(this);
        btnBackup.setOnClickListener(this);
        btnNewRound.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_new:
                mWuziqi.start();
                break;
            case R.id.btn_backp:
                mWuziqi.back();
                break;
            case R.id.btn_leave:
                onBackPressed();
                break;
        }
    }
    @Override
    public void onBackPressed() {
        new AlertDialog.Builder(this).setTitle("提示").setMessage("确定退出本轮比赛?")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                return;
            }
        }).create().show();
    }
}
